<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<mesoBoard.Data.Role>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <fieldset>
        <legend><%= Html.ThemeImage("roles.png") %> Roles</legend>
        
        <fieldset>
            <legend>Create Role</legend>
            <% using(Html.BeginForm("CreateRole", "Roles")){ %>
                <dl class="form">
                    <dt>Name</dt>
                    <dd>
                        <%= Html.TextBox("Name", "") %>
                        <%= Html.ValidationMessage("Name") %>
                    </dd>
                    
                    <dt>Associate a rank</dt>
                    <dd>
                        <%= Html.DropDownList("RankID", "(No Rank)") %>
                    </dd>
                    
                    <dt>&nbsp;</dt>
                    <dd>
                        <%= Html.SubmitButton("CreateRole", "Create Role") %>
                    </dd>
                    
                </dl>
            <% } %>
        </fieldset>
        
        <%= Html.Spacer(5) %>
        <%  Dictionary<string, byte> specialPermissions = new Dictionary<string, byte>()
            {
                {"None", 0},
                {"Moderator", 1},
                {"Administrator", 2}
            }; %>
        <table class="form_table">
        
            <tr>
                <th>Role Name</th>
                <th>Users</th>
                <th>Associated Rank</th>
                <th>Special Permissions</th>
                <th></th>
                <th></th>
            </tr>
            <% foreach(Role r in Model.OrderBy(x=>x.RoleID).Take(3)){ %>
                <tr>
                    <td>(Default) <%= Html.ActionLink(r.Name, "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td><%= Html.ActionLink(r.InRoles.Count.ToString(), "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td><%= r.RankID.HasValue ? r.Rank.Title + (string.IsNullOrWhiteSpace(r.Rank.Image) ? "" : "<br />" + Html.Image("~/Images/Ranks/"+r.Rank.Image).ToString()) : "None" %></td>
                    <td><%= specialPermissions.FirstOrDefault(x=>x.Value == r.SpecialPermissions).Key %></td>
                    <td><%= Html.ActionLink("Edit", "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td>Can't Delete</td>
                </tr>
            <%} %>
            
            <% foreach(Role r in Model.OrderBy(x=>x.RoleID).Skip(3)){ %>
                <tr>
                    <td><%= Html.ActionLink(r.Name, "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td><%= Html.ActionLink(r.InRoles.Count.ToString(), "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td><%= r.RankID.HasValue ? r.Rank.Title + (string.IsNullOrWhiteSpace(r.Rank.Image) ? "" : "<br />" + Html.Image("~/Images/Ranks/" + r.Rank.Image).ToString()) : "None"%></td>
                    <td><%= specialPermissions.FirstOrDefault(x=>x.Value == r.SpecialPermissions).Key %></td>
                    <td><%= Html.ActionLink("Edit", "RoleDetails", new { RoleID = r.RoleID })%></td>
                    <td><%= Html.AdminConfirm("Delete", Url.Action("DeleteRole", new { RoleID = r.RoleID }), Url.Action("Roles")) %></td>
                </tr>
            <%} %>
                    
        </table>
            
    </fieldset>
</asp:Content>
